package model.protocal
{
	import com.adobe.serialization.json.JSON;
	import com.google.maps.LatLng;
	
	import mx.logging.ILogger;
	
	import model.protocal.base.IProtocol;
	import model.vo.TestParserContext;
	
	import utils.LogUtil;
	
	import view.MapCanvas;

	public class LocalGLMProtocal implements IProtocol
	{
		public static var NAME : String = "LocalGLMProtocal.as";
		private var logger:ILogger =  LogUtil.getInst().getLogger( NAME );
		protected var protocalString:String = Global.SERVER_DEVICE_URL + "?action=interface-lbs&cid={0}&lac={1}";
		private var context:TestParserContext;
		
		/**
		 * 
		 * @param lac lac值
		 * @param cid cid值
		 * @param context 上下文
		 * 
		 */		
		public function LocalGLMProtocal(lac:String, cid:String, context:TestParserContext)
		{
			setProtocal(cid, lac);
			this.context = context;
		}
		
		public function getProtocalString():String
		{
			return protocalString;
		}
		
		/**
		 * 设置协议 
		 * @param cid
		 * @param lac
		 * 
		 */		
		public function setProtocal(cid:String, lac:String):void
		{
			this.protocalString = protocalString.replace("{0}", cid).replace("{1}", lac);
		}
		
		/**
		 * 设置返回协议处理函数 
		 * @param evt
		 * 
		 */		
		public function onResponseHandler(evt:Object):void
		{
			logger.info("返回..." + evt.target.data);
			var respData:Object = JSON.decode(evt.target.data);
			if ( this.context != null && respData.status == 1)
			{
				var mapCanvas:MapCanvas = this.context.mapCanvas;
				var data:Object = respData.data;
				
				var endLatLng:LatLng = new LatLng(data.map.latitude, data.map.longitude);
				mapCanvas.setMarker(endLatLng);	
			} else {
				logger.error("获取mapCanvas失败!");			
			}
		}
	}
}